<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('projects', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger("depth")->default(1);
            $table->unsignedBigInteger("department_id");
            $table->string("title");
            $table->boolean("is_show")->default(1);
            $table->unsignedBigInteger("parent_id")->default(0);
            $table->unsignedInteger("order")->default(0);
            $table->unsignedInteger("limit_count")->default(0);
            $table->unsignedInteger("time_interval")->default(0);
            $table->unsignedInteger("project_time")->default(0);
            $table->json("time_range")->nullable();
            $table->timestamps();
        });
        Schema::create('project_has_extra', function (Blueprint $table) {
            $table->id();
            $table->boolean("enable")->default(1);
            $table->unsignedBigInteger("project_id");
            // 日期类型 : 0 : 长期 . 1 : 指定日期
            $table->unsignedInteger("day_type")->default(0);
            // 时间类型 : 0 : 全天 . 1 : 指定时段
            $table->unsignedInteger("time_type")->default(0);
            // 额外类型 : 0 : 休息 . 1 : 加量
            $table->unsignedInteger("extra_type")->default(0);

            // 服务于 日期类型 - 指定日期
            $table->dateTime('start_date')->nullable();
            $table->dateTime('end_date')->nullable();
            // 服务于 时间类型 - 指定时段
            $table->string("start_time")->nullable();
            $table->string("end_time")->nullable();
            $table->json("range_data")->nullable();

            // 用户 额外类型 - 加量
            $table->unsignedInteger("up")->default(0);

            $table->foreign("project_id")
                ->references("id")
                ->on("projects")
                ->cascadeOnDelete();

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('project_has_extra');
        Schema::dropIfExists('projects');
    }
};
